package com.hd.trans.utils;

import android.os.SystemClock;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hd.trans.R;
import com.hd.trans.ui.base.AppContextProvider;

public class HDToastUtil {

    private static String sLastContent;
    private static long sLastShowTime;

    public static void show(String content, int length) {
        if (content.equals(sLastContent) && SystemClock.uptimeMillis() - sLastShowTime < 3000L) {
            return;
        }
        sLastContent = content;
        sLastShowTime = SystemClock.uptimeMillis();

        View view = LayoutInflater.from(AppContextProvider.getContext()).inflate(R.layout.layout_toast_center, null);
        TextView contentTv = (TextView) view.findViewById(R.id.content_tv);
        contentTv.setText(content);
        Toast toast = new Toast(AppContextProvider.getContext());
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(length);
        toast.setView(view);
        toast.show();
    }

    public static void show(String content) {
        show(content, Toast.LENGTH_SHORT);
    }


    public static void show(int resId, int length) {
        show(AppContextProvider.getContext().getString(resId), length);
    }

    public static void show(int resId) {
        show(resId, Toast.LENGTH_SHORT);
    }

}
